<template>
	<view class="content">
		<view class="topBox">
			<view class="title">渠道管理</view>
			<view class="top">
				<view class="left flex">
					<image class="userAvatar" :src="hasLogin?userInfo.avatar:'../../static/images/userAvatar.png'"
						mode="">
					</image>
					<view class="" v-if="hasLogin">
						<view class="flex">
							<text class="text mr32">{{userInfo.nickname}}</text>
							<text class="vip"
								v-if="userInfo.platformLevelDo && userInfo.platformLevelDo.levelName">{{userInfo.platformLevelDo.levelName}}</text>
						</view>
						<view class="flex" style="margin-top: 14rpx;">
							<view class="flex phoneBox">
								<image class="phoneIcon"
									src="https://store-profit-system.oss-cn-shanghai.aliyuncs.com/qudaoguanli/jiaruwomen_icon2.png"
									mode=""></image>
								<view class="text">{{userInfo.phone.substr(0,3) + "****" + userInfo.phone.substr(7)}}
								</view>
							</view>
							<text class="ID" v-if="userInfo.uid!='1001'">ID:{{userInfo.uid}}</text>
						</view>
					</view>
					<view class="mr32" v-else @click="goLogin">请您先登录</view>
				</view>
				<view class="right" @click="goCodePage" v-if="hasLogin">
					<image class="qrcode"
						src="https://store-profit-system.oss-cn-shanghai.aliyuncs.com/qudaoguanli/jiaruwomen_icon9.png"
						mode=""></image>
					<view class="text">推广名片</view>
				</view>
			</view>
		</view>
		<view class="info">
			<image class="bg"
				src="https://store-profit-system.oss-cn-shanghai.aliyuncs.com/qudaoguanli/jiaruwomen_icon15.png"
				mode=""></image>
			<view class="text flex">当前佣金(元）
				<image class="eyes" @click="hidePrice=!hidePrice"
					:src="hidePrice?'https://store-profit-system.oss-cn-shanghai.aliyuncs.com/qudaoguanli/jiaruwomen_icon17.png':'https://store-profit-system.oss-cn-shanghai.aliyuncs.com/qudaoguanli/jiaruwomen_icon16.png'"
					mode=""></image>
			</view>
			<view class="flex">
				<text class="pIcon">￥</text>
				<view class="price">{{hidePrice?'****':dataInfo.commission?dataInfo.commission:0}}</view>
			</view>
			<view class="bottom flex-between">
				<view class="item">
					可推商家余量<view class="num">{{dataInfo.residualMerchant || 0}}</view>
				</view>
				<view class="item">
					已推商家数量<view class="num">{{dataInfo.currentManagement || 0}}</view>
				</view>
				<view class="btn flex-all-center" @click="goGoodsList">
					<image
						src="https://store-profit-system.oss-cn-shanghai.aliyuncs.com/qudaoguanli/jiaruwomen_icon14.png"
						mode=""></image>
					补充余量
				</view>
			</view>
		</view>
		<view class="data">
			<image class="bg"
				src="https://store-profit-system.oss-cn-shanghai.aliyuncs.com/qudaoguanli/jiaruwomen_icon1.png" mode="">
			</image>
			<view class="hide"></view>
			<view class="title flex-between pore">
				<view class="flex">
					<view class="lineText"></view>渠道数据
				</view>
				<text class="rightTitle" @click="hideDetail">{{hideData?'显示':'隐藏'}}数据</text>
			</view>
			<!-- <view class="hide"><text>隐藏数据</text> </view>
			<view class="title flex pore">
				<view class="lineText"></view>渠道数据 
			</view> -->
			<view class="item flex-between pore">
				<view class="itemL">
					今日个人佣金(元)
					<view class="price">
						<text class="pIcon">￥</text>{{hideData?'****':dataInfo.todayIncome?dataInfo.todayIncome:0}}
					</view>
				</view>
				<view class="itemL">
					个人累计业绩(元)
					<view class="price">
						<text
							class="pIcon">￥</text>{{hideData?'****':dataInfo.cumulativePerformance?dataInfo.cumulativePerformance:0}}
					</view>
				</view>
			</view>
			<view class="userItem flex-between pore">
				<view class="left">
					<view class="titleL">
						<image
							src="https://store-profit-system.oss-cn-shanghai.aliyuncs.com/qudaoguanli/jiaruwomen_icon13.png"
							mode=""></image>渠道总人数
					</view>
					<view class="num">{{hideData?'****':dataInfo.channelHeadcount?dataInfo.channelHeadcount:0}}</view>
				</view>
				<view class="left">
					<view class="titleL">
						<image
							src="https://store-profit-system.oss-cn-shanghai.aliyuncs.com/qudaoguanli/jiaruwomen_icon12.png"
							mode=""></image>新增渠道数量
					</view>
					<view class="num">{{hideData?'****':dataInfo.channelNumberToday?dataInfo.channelNumberToday:0}}
					</view>
				</view>
			</view>
			<view class="userItem flex-between pore" style="margin-top: 24rpx;">
				<view class="left">
					<view class="titleL">
						<image class="img"
							src="https://store-profit-system.oss-cn-shanghai.aliyuncs.com/qudaoguanli/jiaruwomen_icon11.png"
							mode=""></image>累计商家数量
					</view>
					<view class="num">{{hideData?'****':dataInfo.numberOfMerchants?dataInfo.numberOfMerchants:0}}</view>
				</view>
				<view class="left">
					<view class="titleL">
						<image class="img"
							src="https://store-profit-system.oss-cn-shanghai.aliyuncs.com/qudaoguanli/jiaruwomen_icon10.png"
							mode=""></image>新增商家数量
					</view>
					<view class="num">
						{{hideData?'****':dataInfo.numberOfMerchantsToday?dataInfo.numberOfMerchantsToday:0}}
					</view>
				</view>
			</view>
		</view>
		<!-- 我的推广 -->
		<view class="promote">
			<view class="title flex">
				<view class="lineText"></view>我的推广
			</view>
			<u-search bgColor="#F8FBFF" v-model="keyword" placeholder="请输入团队成员手机号进行查询" borderColor="#2393FF"
				:showAction="true" actionText="搜索" :animation="true" @search="searchData"
				@custom="searchData"></u-search>
			<!-- <view class="sort">默认排序 <image src="https://store-profit-system.oss-cn-shanghai.aliyuncs.com/qudaoguanli/jiaruwomen_icon7.png" mode=""></image> </view> -->
			<ren-dropdown-filter :filterData='filterData' :defaultIndex='defaultIndex'
				@onSelected='onSelected'></ren-dropdown-filter>
			<view class="" v-if="teamList.length>0">
				<view class="item" v-for="(item,index) in teamList" :key="index">
					<text class="time">加入时间:{{item.createTime}}</text>
					<view class="top">
						<view class="left flex">
							<image class="userAvatar2"
								:src="item.userInfo.avatar?item.userInfo.avatar:'../../static/images/userAvatar.png'"
								mode="">
							</image>
							<view class="">
								<view class="flex">
									<text class=" bName">{{item.userInfo.nickname}}</text>
									<text class="vip" style="padding: 2rpx 20rpx;"
										v-if="item.platformLevelDO && item.platformLevelDO.levelName">{{item.platformLevelDO.levelName}}</text>
								</view>
								<view class="flex phoneBox">
									<image class="phoneIcon" src="@/static/images/phone.png" mode=""></image>
									<view class="bPhone">
										{{item.userInfo.phone.substr(0,3) + "****" + item.userInfo.phone.substr(7)}}
									</view>
								</view>
							</view>
						</view>
						<view class="right">
							<view class="bTotal">累计推广: <text>{{item.pageNumber}}</text></view>
						</view>
					</view>
					<view class="bottom flex-between">
						<view class="bItem">
							<view class="num">
								<text class="pIcon">￥</text>{{item.userInfo.commission}}
							</view>
							累计推广佣金(元)
						</view>
						<view class="bItem">
							<view class="num">
								{{item.pageNumberToday}}
							</view>
							新增推广
						</view>
						<view class="btn" @click="viewTeam(item.userInfo,item.platformLevelDO)">
							查看团队>>>
						</view>
					</view>
				</view>
			</view>
			<view class="" v-else>
				<emptyPage title="暂无信息～"></emptyPage>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		getChannelData
	} from '@/api/user.js';
	import {
		getMyPromotionPage,
		getplatformLevel
	} from '@/api/xing.js';
	import {
		getUserInfo
	} from '@/api/user.js';
	import RenDropdownFilter from '@/components/ren-dropdown-filter/ren-dropdown-filter.vue'
	import emptyPage from '@/components/emptyPage.vue';
	export default {
		components: {
			RenDropdownFilter,
			emptyPage
		},
		data() {
			return {
				userInfo: {phone:'***********'},
				hasLogin: false, //是否登录
				filterData: JSON.parse(uni.getStorageSync('filterData')),
				defaultIndex: [0],
				dataInfo: {},
				hideData: false, //隐藏数据
				hidePrice: false, //隐藏佣金
				page: 1,
				totalPage: 0,
				limit: 10,
				teamList: [],
				keyword: '',
				levelId: ''
			}
		},
		onShow() {
			this.teamList = []
			this.page = 1
			this.getUserList()
		},
		methods: {
			// 获取团队列表
			getTeam() {
				let that = this;
				getMyPromotionPage({
					pageNum: that.page,
					pageSize: that.limit,
					uid: this.userInfo.uid,
					storeId: this.userInfo.msqStore?this.userInfo.msqStore.id:0,
					userPhone: this.keyword,
					levelId: this.levelId
				}).then(res => {
					if (res.data && res.data.records.length > 0) {
						this.teamList = [...this.teamList, ...res.data.records];
						this.totalPage = res.data.pages
					}
				});
			},
			// 点击搜索按钮
			searchData() {
				this.teamList = [];
				this.page = 1;
				this.getTeam()
			},
			//获取用户信息
			getUserList() {
				getUserInfo().then(res => {
					if (res.data) {
						this.userInfo = res.data
						this.hasLogin = true;
						this.getData()
						this.getTeam()
					} else {
						this.hasLogin = false;
						this.goLogin()
					}
				})
			},
			goLogin(){
				console.log(33333333);
				uni.navigateTo({
					url: '/pages/users/wechat_login/index'
				})
			},
			goGoodsList() {
				uni.navigateTo({
					url: "/pages/goods_list/index?goodsTypeId=43"
				})
			},
			viewTeam(item,level) {
				console.log(level);
				let levelName = ''
				if(level&&level.levelName){
					levelName = level.levelName
				}
				uni.navigateTo({
					url: "/pages/users/team/team?levelName="+levelName+"&userInfo=" + encodeURIComponent(JSON.stringify(item))
				})
			},
			// 跳转到推广名片页面
			goCodePage() {
				uni.navigateTo({
					url: '/pages/users/promoteCard/index'
				});
			},
			onSelected(res) {
				this.teamList = []
				this.page = 1
				this.levelId = res[0][0].value
				this.getTeam();
			},
			// 获取渠道数据
			getData() {
				getChannelData(this.userInfo.uid).then(res => {
					this.dataInfo = res.data
				})
			},
			/* 隐藏数据 */
			hideDetail() {
				this.hideData = !this.hideData
			}
		},
		onReachBottom() {
			console.log(666);
			if (this.page < this.totalPage) {
				this.page++;
				this.getTeam();
			}
		},
	}
</script>

<style lang="scss">
	.content {
		padding-bottom: 20rpx;
	}

	.topBox {
		background: #2393FF;
		padding: 108rpx 32rpx 150rpx;
		border-radius: 0 0 30rpx 30rpx;

		.title {
			font-size: 32rpx;
			color: #FFFFFF;
			margin: 0rpx 0 48rpx;
			text-align: center;
		}
	}

	.userAvatar {
		width: 76rpx;
		height: 76rpx;
		border-radius: 50%;
		margin-right: 12rpx;
	}

	.userAvatar2 {
		width: 70rpx;
		height: 70rpx;
		border-radius: 50%;
		margin-right: 12rpx;
	}

	.top {
		width: 100%;
		display: flex;
		align-items: center;
		justify-content: space-between;
		padding-bottom: 24rpx;

		.left {
			.phoneIcon {
				width: 23rpx;
				height: 28rpx;
				margin-right: 6rpx;
			}

			.phoneBox {
				.text {
					
					font-weight: 700;
					font-size: 24rpx;
					color: rgba(255, 255, 255, 0.66);
				}
			}

			.vip {
				border-radius: 4rpx 4rpx 20rpx 4rpx;
				font-weight: 400;
				font-size: 24rpx;
				color: #28314C;
				padding: 2rpx 20rpx;
				background: linear-gradient(91deg, #F2F2F4 0%, #CBCED4 100%);
			}

			.mr32 {
				margin-right: 24rpx;
				color: #FFFFFF;
				font-family: Alibaba PuHuiTi 2.0, Alibaba PuHuiTi 20;
				font-weight: normal;
				font-size: 32rpx;
			}

			.ID {
				
				font-weight: bold;
				font-size: 24rpx;
				color: #FFFFFF;
				background: rgba(255, 255, 255, 0.37);
				border-radius: 8rpx;
				padding: 2rpx 10rpx;
				margin-left: 12rpx;
			}
		}

		.right {
			display: flex;
			flex-direction: column;
			align-items: center;

			.qrcode {
				width: 48rpx;
				height: 48rpx;
				margin-bottom: 8rpx;
			}

			.text {
				font-family: PingFang SC Medium, PingFang SC Medium;
				font-size: 24rpx;
				color: #FFFFFF;
				font-weight: 400;
			}
		}
	}

	.flex {
		display: flex;
		align-items: center;
	}

	.flex-all-center {
		display: flex;
		align-items: center;
		justify-content: center;
	}

	.flex-between {
		display: flex;
		align-items: center;
		justify-content: space-between;
	}

	.info {
		position: relative;
		margin: -126rpx 32rpx 34rpx;
		padding: 38rpx 24rpx;

		.bg {
			width: 686rpx;
			height: 326rpx;
			top: 0;
			left: 0;
			position: absolute;
			z-index: 0;
		}

		.text {
			position: relative;
			z-index: 2;
			font-weight: 500;
			font-size: 24rpx;
			color: #FFFFFF;
			margin-bottom: 10rpx;
		}

		.pIcon {
			position: relative;
			z-index: 2;
			
			font-weight: bold;
			font-size: 26rpx;
			color: #FFFFFF;
			margin: 20rpx 10rpx 0 0;
		}

		.price {
			position: relative;
			z-index: 2;
			
			font-weight: bold;
			font-size: 72rpx;
			color: #FFFFFF;
		}

		.eyes {
			position: relative;
			z-index: 2;
			width: 47rpx;
			height: 29rpx;
			margin-left: 28rpx;
		}

		.bottom {
			position: relative;
			z-index: 2;
			padding-top: 40rpx;

			.item {
				font-weight: 500;
				font-size: 28rpx;
				color: #FFFFFF;

				.num {
					
					font-weight: bold;
					font-size: 32rpx;
					color: #FFFFFF;
				}
			}

			.btn {
				width: 198rpx;
				height: 62rpx;
				background: #FFFFFF;
				border-radius: 16rpx;

				image {
					width: 32rpx;
					height: 32rpx;
					margin-right: 10rpx;
				}

				font-weight: 500;
				font-size: 28rpx;
				color: #2393FF;
			}
		}
	}

	.data {
		position: relative;
		width: 686rpx;
		margin: 0 0 24rpx 32rpx;
		padding: 24rpx;

		.bg {
			position: absolute;
			left: 0;
			top: 0;
			width: 686rpx;
			height: 512rpx;
		}

		.hide {
			padding: 12rpx 24rpx 0 0;
			position: absolute;
			right: 0rpx;
			top: 10rpx;
			width: 324rpx;
			height: 64px;
			background: #D7EEFF;
			border-radius: 12rpx;
			font-size: 24rpx;
			color: #637697;
			z-index: -1;
			text-align: right;
		}

		.title {
			font-weight: 700;
			font-size: 32rpx;
			color: #28314C;
			margin-bottom: 26rpx;
			font-family: "Alibaba PuHuiTi 2.0-85 Bold";

			.rightTitle {
				font-weight: 400;
				font-size: 24rpx;
				color: #637697;
			}
		}

		.lineText {
			width: 8rpx;
			height: 34rpx;
			background: #2393FF;
			border-radius: 4px 4px 4px 4px;
			margin-right: 12rpx;
		}

		.item {

			.itemL {
				width: 50%;
				font-size: 24rpx;
				color: #28314C;
			}

			.price {
				display: flex;
				align-items: flex-end;
				
				font-weight: 700;
				font-size: 56rpx;
				color: #2393FF;
				margin-top: 4rpx;

				.pIcon {
					font-size: 24rpx;
					margin: 0 6rpx 10rpx 0;
				}
			}
		}

		.userItem {
			margin-top: 32rpx;

			.left {
				width: 307rpx;
				height: 122rpx;
				background: #F8FBFF;
				border-radius: 12rpx;
				padding: 14rpx 28rpx 0;

				.titleL {
					display: flex;
					align-items: center;
					font-size: 24rpx;
					color: #28314C;

					image {
						width: 30rpx;
						height: 24rpx;
						margin-right: 6rpx;
					}

					.img {
						width: 30rpx;
						height: 27rpx;
						margin-right: 4rpx;
					}
				}

				.num {
					
					font-weight: 700;
					font-size: 56rpx;
					color: #28314C;
					margin-left: 32rpx;
				}
			}
		}
	}

	.pore {
		position: relative;
		z-index: 1;
	}

	.promote {
		margin: 0 32rpx;
		padding: 32rpx 32rpx;
		background: #FFFFFF;
		box-shadow: 0px 6px 12px 0px rgba(204, 204, 204, 0.1569);
		border-radius: 12rpx;

		.title {
			font-weight: 700;
			font-size: 32rpx;
			color: #28314C;
			margin-bottom: 24rpx;
			font-family: "Alibaba PuHuiTi 2.0-85 Bold"
		}

		.lineText {
			width: 8rpx;
			height: 34rpx;
			background: #2393FF;
			border-radius: 4px 4px 4px 4px;
			margin-right: 12rpx;
		}

		.sort {
			font-size: 24rpx;
			color: #637697;
			padding: 20rpx 0 8rpx 0;
			border-bottom: 2rpx solid #E5E5E5;

			image {
				width: 23rpx;
				height: 21rpx;
				margin-left: 10rpx;
			}
		}

		.item {
			position: relative;
			margin-top: 24rpx;
			padding: 64rpx 24rpx 26rpx;
			background: linear-gradient(180deg, #CCE3FD 0%, #F4F9FF 16%, #FFFFFF 100%);
			box-shadow: 0px 6px 12px 0px rgba(204, 204, 204, 0.1569);
			border-radius: 12rpx;

			.time {
				position: absolute;
				top: 0;
				left: 0;
				background: #0077FF;
				border-radius: 12rpx 0px 16rpx 0px;
				font-size: 20rpx;
				color: #FFFFFF;
				padding: 8rpx 40rpx 8rpx 24rpx;
			}

			.bottom {
				.bItem {
					font-size: 24rpx;
					color: #637697;

					.num {
						
						font-weight: 700;
						font-size: 40rpx;
						color: #2393FF;

						.pIcon {
							font-size: 24rpx;
						}
					}

				}

				.btn {
					width: 178rpx;
					height: 62rpx;
					line-height: 62rpx;
					background: #0077FF;
					border-radius: 42rpx;
					text-align: center;
					font-size: 24rpx;
					color: #FFFFFF;
				}
			}
		}
	}

	.bName {
		color: #28314C;
		margin-right: 24rpx;
		font-family: Alibaba PuHuiTi 2.0, Alibaba PuHuiTi 20;
		font-weight: 700;
		font-size: 28rpx;
	}

	.bPhone {
		
		font-weight: 700;
		font-size: 24rpx;
		color: #637697;
	}

	.bTotal {
		font-size: 24rpx;
		color: #637697;

		text {
			font-family: DIN;
			font-weight: 700;
			font-size: 32rpx;
			color: #637697;
		}
	}
</style>